package com.itheima.eurekaribbonclient.config;

import java.util.List;

import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;

public class MyRule implements IRule {
	
	private ILoadBalancer lb;

	public Server choose(Object key) {

        int number = (int)(Math.random() * 2);
        System.out.println("Choose the number is:" + number);
        
		List<Server> servers = lb.getAllServers();
		
		return servers.get(number);
	}

	public void setLoadBalancer(ILoadBalancer lb) {
		this.lb = lb;
	}

	public ILoadBalancer getLoadBalancer() {
		return this.lb;
	}
}